package pl.nazaweb.jboot.utils;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;

/**
 *
 * @author Marek Kawczyński
 */
public class FileReaderUtils {

    public static int[][] readAllMap(File file) throws FileNotFoundException {
        int array[][] = new int[1000][1000];
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
            String line;
            int row = 0;
            while ((line = bufferedReader.readLine()) != null) {
                readSingleLine(line, array, row);
                row++;
            }
        } catch (Exception e) {
            System.err.println(e.getMessage());
        }
        return array;
    }

    private static void readSingleLine(String line, int[][] array, int row) {
        String[] splitedLine = line.split(";");
        for (int x = 0; x < splitedLine.length; x++) {
            if (splitedLine[x].equals("1")) {
                array[row][x] = 1;
                System.out.println(String.format("%s,%s = jest 1", row, x));
            }
        }
    }
}
